import { menu } from "../../decorator";
import baseColorShap from "./base/baseColorShap";

const { ccclass, property, disallowMultiple, executeInEditMode } = cc._decorator;

@ccclass
@menu(__filename)
@disallowMultiple()
@executeInEditMode()
export default class colorShapCircle extends baseColorShap {

    @property
    _horizontal = false
    @property
    get horizontal() { return this._horizontal }
    set horizontal(value) {
        this._horizontal = value;
        this.updateColorShap();
    }

    @property
    _horizontalSpace = 10
    @property({
        visible(this: colorShapCircle) {
            return this.horizontal;
        }
    })
    get horizontalSpace() { return this._horizontalSpace }
    set horizontalSpace(value) {
        this._horizontalSpace = value;
        this.updateColorShap();
    }

    @property
    _vertical = false
    @property
    get vertical() { return this._vertical }
    set vertical(value) {
        this._vertical = value;
        this.updateColorShap();
    }

    @property
    _verticalSpace = 10
    @property({
        visible(this: colorShapCircle) {
            return this.vertical;
        }
    })
    get verticalSpace() { return this._verticalSpace }
    set verticalSpace(value) {
        this._verticalSpace = value;
        this.updateColorShap();
    }


    constructor() {
        super();
        this._canFill = false;
    }

    overrideDraw(cxt: cc.Graphics, centerX: number, centerY: number) {
        if (this.horizontal || this.vertical) {
            let xMin = centerX - this.node.width * 0.5;
            let xMax = centerX + this.node.width * 0.5;
            let yMin = centerY - this.node.height * 0.5;
            let yMax = centerY + this.node.height * 0.5;

            if (this.horizontal) {
                for (let y = yMin; y <= yMax; y += this.horizontalSpace) {
                    cxt.moveTo(xMin, y);
                    cxt.lineTo(xMax, y);
                }
            }

            if (this.vertical) {
                for (let x = xMin; x <= xMax; x += this.verticalSpace) {
                    cxt.moveTo(x, yMin);
                    cxt.lineTo(x, yMax);
                }
            }
        }
    }
}
